package com.wandian.audio.mvvm.audioTopRank;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.audio.R;
import com.wandian.audio.adapter.AudioTopRankRecycleAdapter;
import com.wandian.audio.bean.TopRankBean;
import com.wandian.audio.databinding.AudioActivityTopRankBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 热门排行榜activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_AUDIO_TOP_RANK)
public class AudioTopRankActivity extends BaseMVVMActivity<AudioTopRankViewModel> {
    private AudioActivityTopRankBinding dataBinding;
    private AudioTopRankRecycleAdapter audioTopRankRecycleAdapter;
    private int pageSize =50;
    private int pageNumber =0;

    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.audio_activity_top_rank);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initRecycle();
        initViewData();
        initClink();
        mViewModel.getMusicTopRank();
    }

    private void initRecycle(){
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
        dataBinding.recycler.setLayoutManager(layoutManager);
        audioTopRankRecycleAdapter  = new AudioTopRankRecycleAdapter(R.layout.audio_item_top_rank_view);
        dataBinding.recycler.setAdapter(audioTopRankRecycleAdapter);
        audioTopRankRecycleAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                TopRankBean.ListEntity bean = (TopRankBean.ListEntity)baseQuickAdapter.getData().get(i);
                if(!UIUtils.isEmpty(bean) && !UIUtils.isEmpty(bean.getId())){
                    ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_AUDIO_TOP_RANK_DETAILS).withString("top_rank_id",bean.getId()+"").navigation();
                }
            }
        });
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("热门榜单");
        mViewModel.listData.observe(this,listBean->{
            if(!UIUtils.isEmpty(listBean)){
                audioTopRankRecycleAdapter.setNewData(listBean);
            }
        });
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> {
            finish();
        });
    }



}
